package com.zmm.util.document.code.controller;

import com.zmm.util.auth.registry.annotation.AuthAnonymous;
import com.zmm.util.document.code.mapping.MappingHandler;
import com.zmm.util.document.register.Interface;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author 900045
 * @description:
 * @name IdoController
 * @date By 2021-10-26 15:35:23
 */
@AuthAnonymous
@RestController
@RequestMapping("/ido")
public class IdoController {

	@Value("${spring.profiles.active}")
	private String           profile;

	@Resource
	protected MappingHandler mappingHandler;

	@Interface(isIgnore = true)
	@RequestMapping("/list")
	public Object list() {
		if (!isTest()) {
			return null;
		}
		return mappingHandler.api(null);
	}

	@Interface(isIgnore = true)
	@RequestMapping("/{code}")
	public Object item(@PathVariable String code) {
		if (!isTest()) {
			return null;
		}
		return mappingHandler.api(code);
	}

	private boolean isTest() {
		return "test".equalsIgnoreCase(profile) || "dev".equalsIgnoreCase(profile);
	}
}
